package me.hekr.iotos.softgateway.subsystem.service;

import lombok.extern.slf4j.Slf4j;
import me.hekr.iotos.softgateway.core.annotation.CloudSendCommand;
import me.hekr.iotos.softgateway.core.config.DeviceRemoteConfig;
import me.hekr.iotos.softgateway.core.klink.ModelData;
import me.hekr.iotos.softgateway.core.subsystem.SubsystemCommandService;
import me.hekr.iotos.softgateway.subsystem.dto.RadioDevice;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * demo 命令测试用例，如果需要处理，则需要在 iot 上物模型中定义一个 demo 的命令
 *
 * @see me.hekr.iotos.softgateway.core.subsystem.SubsystemCommandService#handle(DeviceRemoteConfig,
 *     ModelData)
 * @author iot
 */
@CloudSendCommand
@Slf4j
public class DemoSubSystemCommandServiceImpl implements SubsystemCommandService {
  @Autowired private UdpServerService udpServerService;

  @Override
  public void handle(DeviceRemoteConfig device, ModelData data) {
    log.info("设备收到命令， 设备：{}，命令：{}", device, data);
    RadioDevice dev = RadioDevice.parse(device);
    udpServerService.setVol(dev.getRadioDevId(), (Integer) data.getParam("vol"));
  }
}
